package com.koron.housing.admin.controller;


import com.github.pagehelper.PageInfo;
import com.koron.bean.base.Response;
import com.koron.bean.query.PageQuery;
import com.koron.common.core.config.ThreadLocalContext;
import com.koron.housing.admin.bean.po.HousingAdmin;
import com.koron.housing.admin.bean.query.HousingAdminQuery;
import com.koron.housing.admin.service.HousingAdminService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.koron.ebs.mybatis.ADOConnection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 过渡房管理人员(HousingAdmin)表控制层
 *
 * @author jzp
 * @since 2022-02-26 17:59:40
 */
@Api(tags = "过渡房管理人员接口")
@RestController
@RequestMapping("housingAdmin")
public class HousingAdminController {
    /**
     * 服务对象
     */
    @Autowired
    private HousingAdminService housingAdminService;

    private String getCurrDs() {
        return ThreadLocalContext.get().getCurrDs();
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ApiOperation(value = "根据id查询")
    @GetMapping
    public Response<HousingAdmin> selectOne(@RequestParam String id) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), housingAdminService, "getById", HousingAdmin.class, id));
    }

    @ApiOperation(value = "分页查询")
    @GetMapping("page")
    public Response<PageInfo<HousingAdmin>> page(PageQuery pageQuery, HousingAdminQuery query) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), housingAdminService, "page", PageInfo.class, pageQuery, query));
    }

    @ApiOperation(value = "保存或更新")
    @PostMapping("save")
    public Response<String> save(@RequestBody HousingAdmin admin) {
        ADOConnection.runTask(getCurrDs(), housingAdminService, "save", Boolean.class, admin);
        return Response.ok(admin.getId());
    }

    @ApiOperation(value = "删除数据")
    @DeleteMapping
    public Response<String> delete(@RequestParam String id) {
        ADOConnection.runTask(getCurrDs(), housingAdminService, "deleteById", Boolean.class, id);
        return Response.ok();
    }

}

